package com.agileboot.admin.controller.medicine;


import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.domain.banner.command.HomeBannerCommand;
import com.agileboot.domain.banner.db.HomeBanner;
import com.agileboot.domain.banner.db.HomeBannerService;
import com.agileboot.domain.banner.dto.HomeBannerDTO;
import com.agileboot.domain.banner.query.HomeBannerQuery;
import com.agileboot.domain.medicine.dto.MedicineDTO;
import com.agileboot.domain.medicine.query.MedicineQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 首页banner表(HomeBanner)表控制层
 *
 * @author lx
 * @since 2023-12-08
 */
@Tag(name = "草药API", description = "草药增删查改")
@Validated
@RestController
@RequestMapping("/homeBanner")
public class HomeBannerController {
    /**
     * 服务对象
     */
    @Resource
    private HomeBannerService homeBannerService;

    /**
     * 获取轮播列表
     */
    @Operation(summary = "修改首页轮播图")
//    @PreAuthorize("@permission.has('system:user:list')")
    @PostMapping("/save")
    public ResponseDTO saveHomeBanner(@RequestBody HomeBannerCommand homeBannerCommand) {
        homeBannerService.saveHomeBanner(homeBannerCommand);
        return ResponseDTO.ok();
    }

    /**
     * 获取轮播列表
     */
    @Operation(summary = "首页轮播图列表")
//    @PreAuthorize("@permission.has('system:user:list')")
    @PostMapping("/list")
    public ResponseDTO<PageDTO<HomeBanner>> getHomeBannerList(HomeBannerQuery homeBannerQuery) {
        PageDTO<HomeBanner> homeBannerList = homeBannerService.getHomeBannerList(homeBannerQuery);
        return ResponseDTO.ok(homeBannerList);
    }

    /**
     * 获取轮播列表
     */
    @Operation(summary = "修改首页轮播图")
//    @PreAuthorize("@permission.has('system:user:list')")
    @PostMapping("/edit")
    public ResponseDTO editHomeBanner(@RequestBody HomeBannerCommand homeBannerCommand) {
        homeBannerService.editHomeBanner(homeBannerCommand);
        return ResponseDTO.ok();
    }

    /**
     * 获取轮播列表
     */
    @Operation(summary = "修改首页轮播图状态")
//    @PreAuthorize("@permission.has('system:user:list')")
    @PostMapping("/editStatus")
    public ResponseDTO editHomeBannerStatus(@RequestBody HomeBannerCommand homeBannerCommand) {
        homeBannerService.editHomeBanner(homeBannerCommand);
        return ResponseDTO.ok();
    }

    @Operation(summary = "删除首页轮播")
//    @PreAuthorize("@permission.has('system:user:list')")
    @DeleteMapping("/{ids}")
    public ResponseDTO<Void> delHomeBanner(@PathVariable List<Long> ids) {
        homeBannerService.delHomeBanner(ids);
        return ResponseDTO.ok();
    }


}

